package com.haixiaoke.saas.enterprise.cleaner.controller;

import javax.servlet.http.HttpServletResponse;

import com.haixiaoke.saas.cleaner.domain.InspectionProcessRecord;
import com.haixiaoke.saas.cleaner.domain.InspectionProcessRecordTree;
import com.haixiaoke.saas.cleaner.service.IInspectionProcessRecordService;
import com.haixiaoke.saas.common.annotation.RepeatSubmit;
import com.haixiaoke.saas.common.annotation.TenantScope;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.tenant.TenantContext;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.house.domain.HouseInspection;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 验房流程记录Controller
 *
 * @author xiaolong
 * @date 2024-05-10
 */
@RestController
@RequestMapping("/enterprise/cleaner/record")
public class EnterpriseInspectionProcessRecordController extends BaseController {
    @Autowired
    private IInspectionProcessRecordService inspectionProcessRecordService;

    /**
     * 查询验房流程记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(InspectionProcessRecord inspectionProcessRecord) {
        startPage();
        List<InspectionProcessRecord> list = inspectionProcessRecordService.selectInspectionProcessRecordList(inspectionProcessRecord);
        return getDataTable(list);
    }

    /**
     * 导出验房流程记录列表
     */
    @PostMapping("/export")
    @RepeatSubmit
    public void export(HttpServletResponse response, InspectionProcessRecord inspectionProcessRecord) {
        List<InspectionProcessRecord> list = inspectionProcessRecordService.selectInspectionProcessRecordList(inspectionProcessRecord);
        ExcelUtil<InspectionProcessRecord> util = new ExcelUtil<InspectionProcessRecord>(InspectionProcessRecord.class);
        util.exportExcel(response, list, "验房流程记录数据");
    }

    /**
     * 获取验房流程记录详细信息
     */
    @GetMapping(value = "/{inspectionProcessId}")
    public AjaxResult getInfo(@PathVariable("inspectionProcessId") Long inspectionProcessId) {
        return success(inspectionProcessRecordService.selectInspectionProcessRecordByInspectionProcessId(inspectionProcessId));
    }

    /**
     * 新增验房流程记录
     */
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody InspectionProcessRecord inspectionProcessRecord) {
        return toAjax(inspectionProcessRecordService.insertInspectionProcessRecord(inspectionProcessRecord));
    }

    /**
     * 修改验房流程记录
     */
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@RequestBody InspectionProcessRecord inspectionProcessRecord) {
        return toAjax(inspectionProcessRecordService.updateInspectionProcessRecord(inspectionProcessRecord));
    }

    /**
     * 删除验房流程记录
     */
    @DeleteMapping("/{inspectionProcessIds}")
    @RepeatSubmit
    public AjaxResult remove(@PathVariable Long[] inspectionProcessIds) {
        return toAjax(inspectionProcessRecordService.deleteInspectionProcessRecordByInspectionProcessIds(inspectionProcessIds));
    }

    /**
     * 查询保洁流程列表
     */
    @GetMapping("/tree")
    @TenantScope
    public TableDataInfo tree(InspectionProcessRecord inspectionProcessRecord) {
        startPage();
        inspectionProcessRecord.setTenantId(TenantContext.getTenantId());
        List<InspectionProcessRecordTree> list = inspectionProcessRecordService.selectInspectionProcessRecordTree(inspectionProcessRecord);
        return getDataTable(list);
    }
}
